﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PHTShop.admin
{
    public partial class content_aboutus : System.Web.UI.Page
    {
        private DataContextDataContext dc = new DataContextDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "Change about us content";
            
            if (!IsPostBack)
            {
                Content content_E = dc.Contents.Single(z => z.name.Equals("about") && z.idlanguage==1);
                HiddenField1.Value = content_E.id.ToString();
                TextboxContent_E.Value = content_E.details;

                Content content_F = dc.Contents.Single(z => z.name.Equals("about") && z.idlanguage == 2);
                HiddenField2.Value = content_F.id.ToString();
                TextboxContent_F.Value = content_F.details;

                Content content_G = dc.Contents.Single(z => z.name.Equals("about") && z.idlanguage == 3);
                HiddenField3.Value = content_G.id.ToString();
                TextboxContent_G.Value = content_G.details;
               
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string aboutE=TextboxContent_E.Value.Trim();
            string aboutF=TextboxContent_F.Value.Trim();
            string aboutG=TextboxContent_G.Value.Trim();
            if (string.IsNullOrEmpty(aboutE) && string.IsNullOrEmpty(aboutF) && string.IsNullOrEmpty(aboutG))
            {
                Label1.Text = "Data can not be empty";
            }
            else {

                if (string.IsNullOrEmpty(aboutE))
                {
                    updateContent(" ", 1);
                }
                else {
                    updateContent(aboutE, 1);
                }

                if (string.IsNullOrEmpty(aboutF))
                {
                    updateContent(" ", 2);
                }
                else
                {
                    updateContent(aboutF, 2);
                }

                if (string.IsNullOrEmpty(aboutG))
                {
                    updateContent(" ", 3);
                }
                else
                {
                    updateContent(aboutG, 3);
                }
                Response.Redirect("Index.aspx");
            }
        }

        private void updateContent(string content,int languagle) {

            Content c = dc.Contents.SingleOrDefault(z=>z.name.Equals("about") && z.idlanguage==languagle);
            c.details = content;
            dc.SubmitChanges();
        }
    }
}